using System;
using GameFramework.Reference;

namespace Server.Proto
{
    [Flags]
    public enum ServerFlags
    {
        /// <summary>
        /// 维护
        /// </summary>
        Maintenance = 1 << 0,
        
        /// <summary>
        /// 推荐
        /// </summary>
        Recommend = 1 << 1,
        
        /// <summary>
        /// 新服
        /// </summary>
        New = 1 << 2,
    }
    
    /// <summary>
    /// 服务器信息
    /// </summary>
    public class ServerInfo : AReference
    {
        /// <summary>
        /// 服务器id
        /// </summary>
        public int Id;
        
        /// <summary>
        /// 服务器开服时间
        /// </summary>
        public DateTime OpenTime;
        
        /// <summary>
        /// 服务器标记
        /// </summary>
        public ServerFlags Flags;
        
        /// <summary>
        /// 服务器ip
        /// </summary>
        public string Ip;
        
        /// <summary>
        /// 服务器端口
        /// </summary>
        public int Port;

        public override void OnRecycle()
        {
            Id = default;
            OpenTime = default;
            Flags = default;
            Ip = string.Empty;
            Port = default;
        }

        public bool IsValid()
        {
            if (Id == 0)
                return false;
            
            if (string.IsNullOrEmpty(Ip))
                return false;
            
            if (Port == 0)
                return false;
            
            return true;
        }
    }
}